package dao

import (
	"fmt"
	"gin/CloudRestaurant/model"
	"gin/CloudRestaurant/tool"
	//"github.com/goes/logger"
)

type MemberDao struct {
	*tool.Orm
}
//验证会员表中是否有成员信息
func (md *MemberDao)QuerByPhone(phone string)*model.Member  {
	var member model.Member
	if _,err := md.Where("model = ?",phone).Get(&member);err!= nil{
		fmt.Println(err.Error())
	}
	return &member
}
// 验证手机号和验证码是否存在
func (md *MemberDao) ValidateSmsCode(phone string,code string) *model.SmsCode  {
	var sms model.SmsCode
	if _,err := md.Where("phone = ? and code =?",phone,code).Get(&sms);err != nil{
		fmt.Println(err.Error())
	}
	return &sms
}

// 插入一条验证码信息
func (md *MemberDao) InsertCode(sms model.SmsCode) int64  {
	result,err := md.InsertOne(&sms)
	if err != nil{
		fmt.Println(err.Error())
	}
	return  result
}
// 插入一条会员信息
func (md *MemberDao) InsertMemver(member model.Member) int64  {
	result,err := md.InsertOne(&member)
	if err != nil{
		fmt.Println(err.Error())
		return 0
	}
	return result
}
